package com.net.xpay.alipay.flexible;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

@Slf4j
//@Configuration
public class FlexibleCoreConfig {

    @Autowired
    private FlexibleAlipayProperties flexibleAlipayProperties;

    /**
     * 零工卡视频核验 开卡等
     */
    @Bean
    public FlexibleAlipayClient flexibleAlipayClient() throws AlipayApiException {
        String url = flexibleAlipayProperties.getAlipayTopUrl();
        String appId = flexibleAlipayProperties.getAlipayAppId();
        String appPrivateKey = flexibleAlipayProperties.getAppPrivateKey();
        String alipayPublicKey = flexibleAlipayProperties.getAlipayPublicKey();

        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setPrivateKey(appPrivateKey);
        alipayConfig.setAppId(appId);
        alipayConfig.setServerUrl(url);
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        alipayConfig.setFormat("json");

        DefaultAlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);

        return new FlexibleAlipayClient(alipayClient, flexibleAlipayProperties);
    }
}
